// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import SaveManager from "../../Managers/SaveManager";
import UIManager from "../../Managers/UIManager";
import SigninManager from "../../Models/Signins/SigninManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SigninItem extends cc.Component {

    @property(cc.Label)
    dayTxt: cc.Label = null;
    @property(cc.Label)
    amountTxt: cc.Label = null;
    @property(cc.Toggle)
    itemToggle: cc.Toggle = null;

    day: number = 0;
    protected onLoad(): void {

    }

    drawItem(i: number, obj: any) {
        this.day = i;
        var userdata = SaveManager.single.userdata;
        this.dayTxt.string = "第@天".replace("@", (this.day + 1).toString());
        this.amountTxt.string = "x" + obj.amount;
        // if (this.day < SaveManager.single.userdata.signinDay) {
        //     this.itemToggle.isChecked = true;
        // } else if (this.day == SaveManager.single.userdata.signinDay) {
        //     this.itemToggle.isChecked = SaveManager.single.userdata.isSignin;
        // } else {
        //     this.itemToggle.isChecked = false;
        // }
        this.itemToggle.isChecked = userdata.signinArr[i].isReceive;
        this.itemToggle.interactable = this.day == userdata.signinDay && !userdata.isSignin;
    }

    signinClick() {
        var userdata = SaveManager.single.userdata;
        if (userdata.isSignin) {
            UIManager.single.showTips("今日已签到。");
            this.itemToggle.isChecked = true;
            return;
        }
        SigninManager.single.requestSignin(this.day);
    }
}
